# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /bin/bash

ARCH                        = $(shell uname -m)
OS_VERSION                 ?= pike
DOCKER_REGISTRY            ?= docker.io
IMAGE_PREFIX               ?= starlingx4arm
IMAGE_NAME                 ?= neutron
IMAGE_TAG                  ?= centos-${OS_VERSION}-${ARCH}
FROM                       ?= ${IMAGE_PREFIX}/centos:7-${ARCH}

IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG}	

IMAGES = nova neutron keystone glance horizon heat
.PHONY: $(IMAGES)

all: $(IMAGES)

$(IMAGES):	
	echo "===== Processing [$@] chart =====";
	make build-$@
	docker push ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/$@:${IMAGE_TAG}

all: image push
.PHONY: all

push:
	docker push $(IMAGE)
.PHONY: push

build-neutron:
	docker build --force-rm --pull --no-cache \
    ./loci \
    --build-arg PROJECT=neutron \
    --build-arg FROM=${FROM} \
	--build-arg PROJECT_REF=stable/${OS_VERSION}  \
	--build-arg PROJECT_REPO=https://gitee.com/mirrors/neutron.git \
    --build-arg PROFILES="fluent neutron linuxbridge openvswitch" \
    --build-arg PIP_PACKAGES="networking-sfc pycrypto pylint tinyrpc lxml" \
    --build-arg WHEELS=http://172.17.0.3/workspace/stx-centos-stable-wheels.tar \
    --tag ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/neutron:${IMAGE_TAG}
.PHONY: build-neutron

build-nova:
	docker build --force-rm --pull --no-cache \
    ./loci \
    --build-arg PROJECT=nova \
    --build-arg FROM=${FROM} \
	--build-arg PROJECT_REF=stable/${OS_VERSION}  \
	--build-arg PROJECT_REPO=https://gitee.com/mirrors/nova.git \
    --build-arg PROFILES="fluent nova ceph linuxbridge openvswitch configdrive qemu apache" \
    --build-arg PIP_PACKAGES="pycrypto httplib2 pylint python-ironicclient" \
    --build-arg DIST_PACKAGES="openssh-clients openssh-server libvirt e2fsprogs" \
    --build-arg WHEELS=http://172.17.0.3/workspace/stx-centos-stable-wheels.tar \
    --tag ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/nova:${IMAGE_TAG}
.PHONY: build-nova

build-keystone:
	docker build --force-rm --pull --no-cache \
    ./loci \
    --build-arg PROJECT=keystone \
    --build-arg FROM=${FROM} \
	--build-arg PROJECT_REF=stable/${OS_VERSION}  \
	--build-arg PROJECT_REPO=https://gitee.com/mirrors/keystone.git \
    --build-arg PROFILES="fluent apache ldap" \
    --build-arg PIP_PACKAGES="pycrypto python-openstackclient ldap ldappool python-ldap pylint" \
    --build-arg WHEELS=http://172.17.0.3/workspace/stx-centos-stable-wheels.tar \
    --tag ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/keystone:${IMAGE_TAG}
.PHONY: build-keystone

build-heat:
	docker build --force-rm --pull --no-cache \
    ./loci \
    --build-arg PROJECT=heat \
    --build-arg FROM=${FROM} \
	--build-arg PROJECT_REF=stable/${OS_VERSION}  \
	--build-arg PROJECT_REPO=https://gitee.com/mirrors/heat.git \
    --build-arg PROFILES="fluent heat apache" \
    --build-arg PIP_PACKAGES="pycrypto pylint" \
    --build-arg DIST_PACKAGES="curl" \
    --build-arg WHEELS=http://172.17.0.3/workspace/stx-centos-stable-wheels.tar \
    --tag ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/heat:${IMAGE_TAG}
.PHONY: build-heat

build-glance:
	docker build --force-rm --pull --no-cache \
    ./loci \
    --build-arg PROJECT=glance \
    --build-arg FROM=${FROM} \
	--build-arg PROJECT_REF=stable/${OS_VERSION}  \
	--build-arg PROJECT_REPO=https://gitee.com/mirrors/glance.git \
    --build-arg PROFILES="fluent glance ceph" \
    --build-arg PIP_PACKAGES="pycrypto python-swiftclient" \
    --build-arg DIST_PACKAGES="postgresql-libs" \
    --build-arg WHEELS=http://172.17.0.3/workspace/stx-centos-stable-wheels.tar \
    --tag ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/glance:${IMAGE_TAG}
.PHONY: build-glance

build-horizon:
	docker build --force-rm --pull --no-cache \
    ./loci \
    --build-arg PROJECT=horizon \
    --build-arg FROM=${FROM} \
	--build-arg PROJECT_REF=stable/${OS_VERSION}  \
	--build-arg PROJECT_REPO=https://gitee.com/mirrors/horizon.git \
    --build-arg PROFILES="fluent horizon apache" \
    --build-arg PIP_PACKAGES="pycrypto python-ceilometerclient coverage pyudev ldap pylint" \
    --build-arg WHEELS=http://172.17.0.3/workspace/stx-centos-stable-wheels.tar \
    --tag ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/horizon:${IMAGE_TAG}
.PHONY: build-horizon